<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed!');

class Jeasyui {

	function treefy($data, $options = array())
	{
		$pk = isset($options['pk']) ? $options['pk'] : 'id';
		$fk = isset($options['fk']) ? $options['fk'] : 'parent_id';
		$sw = isset($options['sw']) ? $options['sw'] : 0;

		$nodes = $this->_build_tree($data, $pk, $fk, $sw);
		return $nodes;
	}

	private function _build_tree($data, $pk, $fk, $sw)
	{
		$nodes = array();
		
		if (count($data) > 0)
		{
			foreach($data as $row)
			{
				if ($row->$fk == $sw)
				{
					$nodes[] = $row;
				}
			}
		}
		return $nodes;
	}



}